/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-26
 * Time: 23:51
 */
public enum Color {
    RED("RED",0),PICK("PICK",1),
    BLACK("BLACK",2),BLUE("BLUE",3);//枚举对象

    public String str;
    public  int i;
     Color(String color,int i) {
        this.str = color;
        this.i = i;
    }
    public static void main(String[] args) {
        Color[] colors = Color.values();//将枚举对象转化为数组
        for (Color color : colors) {
            System.out.println(color+" "+color.ordinal());//获取索引
        }
        System.out.println("====");
        Color color = Color.valueOf("RED");//将字符串转化为枚举对象
        System.out.println(color);

        System.out.println("===");
        System.out.println(RED.compareTo(PICK));//比较枚举对象的定义顺序（下标差）
    }

    public static void main1(String[] args) {
        Color color = RED;
        switch (color) {
            case RED :
                System.out.println(RED);
                break;
            case BLACK :
                System.out.println(BLACK);
                break;
            case PICK:
                System.out.println(PICK);
                break;
            case BLUE:
                System.out.println(BLUE);
                break;
            default:
                System.out.println("null");
                break;
        }
    }
}

